#!/bin/bash
BIN_DIR=`pwd`
export JAVA_HOME=/usr/local/java/jdk1.8.0_181
ES_ID=`ps -ef |grep elasticsearch |grep -w 'elastic+'|grep -v 'grep'|awk '{print $2}'`
StartES=`sudo service elasticsearch start`
ESMonitorLog='/var/log/maestro/es_auto_restart.log'
ES_ID=$(echo $ES_ID|tr -d '\n')

Monitor()
{
  if [[ $ES_ID ]];then
    echo "[info]["`date "+%Y-%m-%d %H:%M:%S"`"]當前ElasticSearch進程ID為:$ES_ID"
  else
    echo "[error]["`date "+%Y-%m-%d %H:%M:%S"`"]ElasticSearch進程不存在!ElasticSearch開始自動重啟..."
    $StartES
  fi
}
Monitor>>$ESMonitorLog